package annotation.load;

public class GetClassLoader {

    public static void main(String[] args) throws ClassNotFoundException {
        //获取系统类加载器
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
        System.out.println(systemClassLoader);

        //获取系统类加载器的父类-->扩展类加载器
        ClassLoader parent = systemClassLoader.getParent();
        System.out.println(parent);

        //获取扩展类加载器的父类-->引导类加载器
        ClassLoader rootLoader = parent.getParent();
        System.out.println(rootLoader);

        //测试当前类加载器
        Class thisClass = Class.forName("annotation.load.GetClassLoader");
        ClassLoader classLoader = thisClass.getClassLoader();
        System.out.println(thisClass);
        System.out.println(classLoader);

        //测试JDK内置类加载器
        ClassLoader loader = Class.forName("java.lang.Object").getClassLoader();
        System.out.println(loader);

        //如何获得系统类加载器可以加载的路径？
        System.out.println(System.getProperty("java.class.path"));

        //双亲委派机制
    }
}
